//app.js
var qcloud = require('./vendor/wafer2-client-sdk/index')
var config = require('./config')
App({
  onLaunch: function () {
    qcloud.setLoginUrl(config.service.loginUrl)
  },
  globalData: {
    host: config.service.host,
    userInfo: {},
    shopInfo: {},
    _shopId: '',
    _goodsId: '',
    cartInfo:[],
    goodsInfo: {},
    inventoryId: {},
    count:0,
    radioValue:''
  },
  toIndex: function () {
    wx.redirectTo({
      url: '../index/index'
    })
  },
  toOpen:function() {
    wx.redirectTo({
      url: '../open/open'
    })
  },
  toCart: function(goodsId) {
    wx.redirectTo({
      url: '../shopping-cart/shopping-cart?goodsId=' + goodsId
    })
  },
  toPay: function (orderId) {
    wx.redirectTo({
      url: '../pay-sucess/pay-sucess?orderId=' + orderId
    })
  },
  toGoodsDetail:function(id) {
    wx.navigateTo({
      url: '../commodity-details/commodity-details?goodsId=' + id
    })
  },
  showToastNone: function (name,time) {
    if(!time){
      time = 500;
    }
    wx.showToast({ title: name, icon: 'none', duration: time })
  },
  changeCart: function (shop_id, session_key,goods_id,type,num) {
    var that = this;
    wx.showLoading({
      title: '处理中',
      duration: 200
    })
    wx.request({
      url: config.service.host + '/cart/changeCart',
      data: {
        'shop_id': shop_id,
        'session_key': session_key,
        'goods_id': goods_id,
        'type': type,
        'num': num,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        let data = res.data
        if(data.code == 2000){
        }else{
          wx.showToast({ title: data.msg, icon: 'none', duration: 2000 })
        }
      }
    })
  }
})